using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for TableBll
/// </summary>
public class TableBll
{
	public TableBll()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    #region List Table of Restaurant
    public SqlDataReader ListTableByRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@resID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = resInfo.ResID;
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Table_ListTableByRestaurant", cmdParms);
    }
    #endregion

    #region List all Table
    public SqlDataReader ListAllTable()
    {
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Table_ListAll", null);
    }
    #endregion

    #region Create new Table
    public int CreateTable(TableInfo tableInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@tableID", SqlDbType.VarChar, 10),
                new SqlParameter("@numberOfPerson", SqlDbType.Int),
                new SqlParameter("@price", SqlDbType.Float),
                new SqlParameter("@resID", SqlDbType.VarChar, 10),
                new SqlParameter("@tablePicture", SqlDbType.VarChar, 200),
                new SqlParameter("@tableDescription", SqlDbType.VarChar, 1000)
            };
        cmdParms[0].Value = tableInfo.TableID;
        cmdParms[1].Value = tableInfo.NumberOfPerson;
        cmdParms[2].Value = tableInfo.Price;
        cmdParms[3].Value = tableInfo.ResID;
        cmdParms[4].Value = tableInfo.TablePicture;
        cmdParms[5].Value = tableInfo.TableDescription;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Table_Create", cmdParms);

        return result;
    }
    #endregion

    #region Update Table's Information
    public int UpdateTable(TableInfo tableInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@tableID", SqlDbType.VarChar, 10),
                new SqlParameter("@numberOfPerson", SqlDbType.Int),
                new SqlParameter("@price", SqlDbType.Float),
                new SqlParameter("@resID", SqlDbType.VarChar, 10),
                new SqlParameter("@tablePicture", SqlDbType.VarChar, 200),
                new SqlParameter("@tableDescription", SqlDbType.VarChar, 1000)
            };
        cmdParms[0].Value = tableInfo.TableID;
        cmdParms[1].Value = tableInfo.NumberOfPerson;
        cmdParms[2].Value = tableInfo.Price;
        cmdParms[3].Value = tableInfo.ResID;
        cmdParms[4].Value = tableInfo.TablePicture;
        cmdParms[5].Value = tableInfo.TableDescription;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Table_Update", cmdParms);

        return result;
    }
    #endregion

    #region Delete Table
    public int DeleteTable(TableInfo tableInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@tableID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = tableInfo.TableID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Table_Delete", cmdParms);
        return result;
    }
    #endregion
}
